#include "displayFunc.cpp"

void mainDisplay(){
	glutSetWindow(mainWindow);
	glClear(GL_COLOR_BUFFER_BIT  | GL_DEPTH_BUFFER_BIT);
	glutSwapBuffers();
}
void gameDisplay(){
	glutSetWindow(gameWindow);
	glClear(GL_COLOR_BUFFER_BIT  | GL_DEPTH_BUFFER_BIT);
	drawMovingPiece();
	drawStationaryPieces();
	drawHighlights();
	drawBoard();
	glutSwapBuffers();
}
void menuDisplay(){
	glutSetWindow(menuWindow);
	glClear(GL_COLOR_BUFFER_BIT  | GL_DEPTH_BUFFER_BIT);
	drawMenu();
	glutSwapBuffers();
}
void initMainWin(){
	glClearColor(0.0,0.0,0.0,1.0);
	
	glShadeModel(GL_SMOOTH);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_NORMALIZE);
	glEnable(GL_BLEND);
	
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(60.0,((float)width/(float)height),1.0,400.0);

	moveCamera();
}
void initGameWin(){
	glClearColor(0.0,0.0,0.0,1.0);
	
	glShadeModel(GL_SMOOTH);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_NORMALIZE);
	glEnable(GL_BLEND);
	
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(60.0,((float)width/(float)height),1.0,400.0);

	moveCamera();

	initLightsMats();
	initTex();
}
void initMenuWin(){
	glClearColor(1.0,1.0,1.0,1.0);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0,1,0,1,-1,1);
	
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();	

	gluLookAt(0,0,1, 0,0,0, 0.0,1.0,0.0);
	menuText = SOIL_load_OGL_texture("menu.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y);
}
int main(int argc, char **argv){
	PieceManager temp;
	pieceman = &temp;
	pieceman->autoSetup();

	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
	glutInitWindowSize(width,height);
	
	mainWindow = glutCreateWindow("Towers of Hanoi - Program 7 - Patrick Smyth");
	glutDisplayFunc(mainDisplay);
	initMainWin();
	
	gameWindow = glutCreateSubWindow(mainWindow, width*.25, 0, width*.75, height);
	glutDisplayFunc(gameDisplay);
	glutMouseFunc(mouseFunction);
	glutPassiveMotionFunc(passiveMotionFunction);
	glutKeyboardFunc(keyboard);
	glutSpecialFunc(special);
	glutTimerFunc(20,timer,1);
	initGameWin();
	
	menuWindow = glutCreateSubWindow(mainWindow, 0, 0, width*.25, height);
	glutDisplayFunc(menuDisplay);
	initMenuWin();

	glutMainLoop();
	
	return 0;
}
